/***********************************************************************************************************************************
 * Name:	SQLVersion.sql
 * Author:	Frank Figearo (frank@sqlnerd.me)
 * Summary:	Parse the SQL Server version information into Major.Minor.Build
 */
SET IMPLICIT_TRANSACTIONS OFF; WHILE 0 < @@TRANCOUNT ROLLBACK;
GO
DECLARE @major TINYINT, @minor TINYINT, @build SMALLINT, @version DECIMAL(5,2);
SELECT
	@major= (@@MicrosoftVersion & 0xFF000000) / 0x01000000,
	@minor= (@@MicrosoftVersion & 0x00FF0000) / 0x00010000,
	@build= (@@MicrosoftVersion & 0x0000FFFF) / 0x00000001;

SET @version= @minor;
WHILE 1 <= @version SET @version= @version/10;
SET @version= @major+@version;

SELECT [major]= @major, [minor]= @minor, [build]= @build, [version]= @version;
GO